/**
 * @Author: SevDaisy十七散人 
 * @Date: 2020-07-05 12:03:31
 * @Last Modified time: 2020-07-05 12:03:31
 */
package zyy.ui;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;

public class FrmReload extends JFrame implements ActionListener {
  private static final long serialVersionUID = -5537968844666670589L;
  private JMenuBar menubar = new JMenuBar();
  private JMenu menu_Choose = new JMenu("选择界面");
  private JMenuItem menuItem_Rider = new JMenuItem("骑手");
  private JMenuItem menuItem_Store = new JMenuItem("商家");
  private JLabel lRider = new JLabel("我是骑手");
  private JLabel lStore = new JLabel("我是商家");
  private JPanel Route = new JPanel();
  // public Font(String familyName,int style,int size)
  // private Font font = new Font("STKaiti Regular", Font.BOLD, 37);

  public void refeshRoute(String type) {
    this.Route.removeAll();
    JPanel workPane = new JPanel();
    switch (type) {
      case "商家":
        workPane.add(this.lStore);
        // this.setSize(200, 200);
        break;
      case "骑手":
        workPane.add(this.lRider);
        // this.setSize(100, 100);
        break;
      default:
        workPane.add(this.lRider);
        // this.setSize(100, 100);
        break;
    }
    workPane.setLayout(new FlowLayout(FlowLayout.LEFT));
    this.Route.add(workPane, BorderLayout.CENTER);
    // this.revalidate();
    // this.repaint();
    // this.invalidate();
    this.Route.updateUI();
    // this.Route.invalidate();
  }

  @Override
  public void actionPerformed(ActionEvent e) {
    if (e.getSource() == this.menuItem_Rider) {
      refeshRoute("骑手");
    } else if (e.getSource() == this.menuItem_Store) {
      refeshRoute("商家");
    }

  }

  public FrmReload() {
    {
      // JFrame 基础设置
      // this.setExtendedState(Frame.MAXIMIZED_HORIZ);// 拓展状态
      this.setSize(200, 160);
      this.setTitle("Demo 刷新主页面");// 标题
      this.setLocationRelativeTo(null); // 居中
      this.setVisible(true);
    }
    {
      // 菜单栏 设置
      this.setJMenuBar(menubar);
      menubar.add(menu_Choose);
      menu_Choose.add(menuItem_Store);
      menu_Choose.add(menuItem_Rider);
      menuItem_Rider.addActionListener(this);
      menuItem_Store.addActionListener(this);
    }
    {
      // 路由框 JPanel::Route 设置
      Route.setLayout(new BorderLayout());
      {
        // 初始化
        JPanel workPane = new JPanel();
        workPane.add(this.lStore);
        workPane.setLayout(new FlowLayout(FlowLayout.LEFT));
        this.Route.add(workPane, BorderLayout.CENTER);
      }
      this.getContentPane().add(Route, BorderLayout.CENTER);
      this.Route.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
          Route.updateUI();
        }
      });
    }
    {
      // 页面设置
      lRider.setFont(new Font("STKaiti Regular", Font.BOLD, 37));
      lStore.setFont(new Font("STKaiti Regular", Font.BOLD, 37));
    }
  }

  public static void main(String[] args) {
    new FrmReload();
  }
}